﻿<script type="text/javascript">
    function initcombo() {
        @*// 分中心分站联动
        $("#Center").combobox({
            url: '@Url.Content("~/Medical/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            prompt: '--请选择--',
            editable: false,
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                $("#Station").combobox({
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    prompt: '--请选择--',
                    editable: false
                });
            }
        });*@
        @*// 分中心分站联动
        $("#Center").combobox({
            url: '@Url.Content("~/CM/Violation/GetCenter/")',
            valueField: 'ID',
            textField: 'Name',
            prompt: '--请选择--',
            editable: false,
            onSelect: function (rec) {
                var urlstation = '@Url.Content("~/CM/Violation/GetStationByCenter?centerID=")' + rec.ID;
                $("#Station").combobox({
                    url: urlstation,
                    valueField: 'ID',
                    textField: 'Name',
                    prompt: '--请选择--',
                    editable: false
                });
            }
        });*@
        //选择车牌号码取出对应的车辆编号和车辆编码
        $("#ActualCode").combobox({
            url: '@Url.Content("~/CM/Refuel/GetActualCode?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',
            valueField: 'Name',
            textField: 'Name',
            editable: true,
            prompt: '--请选择--',
            filter: function (q, row) {
                var opts = $('#ActualCode').combobox('options');
                return row[opts.textField].indexOf(q) > -1;
            },
            onSelect: function (rec) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/Refuel/GetListByActualCode")',
                    data:
                        {
                            actualCode: rec.Name
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $('#AmbulanceCode').val(jsData.model.AmbulanceCode);
                        $('#AmbulanceNumber').combobox('setText', jsData.model.AmbulanceNumber);
                        $('#Center').val(jsData.model.CenterID);
                        $('#Station').val(jsData.model.StationID);
                        //$('#Center').combobox("setValue", jsData.model.CenterID);
                        //$('#Station').combobox("setValue", jsData.model.StationID);
                        //$('#Center').combobox("setText", jsData.model.Center);
                        //$('#Station').combobox("setText", jsData.model.Station);
                    }
                });
            },
            onChange: function () {
                $('#AmbulanceNumber').combobox('clear');               
                //$('#Center').combobox('clear');
                //$('#Station').combobox('clear');
            }
        });
        //选择车辆编号取出对应的车牌号码和车辆编码
        $("#AmbulanceNumber").combobox({
            url: '@Url.Content("~/CM/Refuel/GetAmbulanceNumber?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',
            valueField: 'Name',
            textField: 'Name',
            editable: true,
            prompt: '--请选择--',
            filter: function (q, row) {
                var opts = $('#AmbulanceNumber').combobox('options');
                return row[opts.textField].indexOf(q) > -1;
            },
            onSelect: function (rec) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/Refuel/GetListByAmbulanceNumber")',
                    data:
                        {
                            ambulanceNumber: rec.Name
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $('#ActualCode').combobox('setText', jsData.model.ActualCode);
                        $('#AmbulanceCode').val(jsData.model.AmbulanceCode);
                        $('#Center').val(jsData.model.CenterID);
                        $('#Station').val(jsData.model.StationID);
                        //$('#Center').combobox("setValue", jsData.model.CenterID);
                        //$('#Station').combobox("setValue", jsData.model.StationID);
                        //$('#Center').combobox("setText", jsData.model.Center);
                        //$('#Station').combobox("setText", jsData.model.Station);
                    }
                });
            },
            onChange: function () {
                $('#ActualCode').combobox('clear');              
                //$('#Center').combobox('clear');
                //$('#Station').combobox('clear');
            }
        });
        //司机工号和姓名联动
        $('#DriverWorkID').combobox({
            prompt: '--请选择--',
            url: '@Url.Content("~/CM/CardInfo/GetDriverWorkID?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',//ajax后台取数据路径，返回的是json格式的数据
            valueField: 'Name',
            textField: 'Name',
            method: 'POST',
            onSelect: function (rec) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/CardInfo/GetListByWorkID")',
                    data:
                        {
                            workID: rec.Name
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $('#DriverName').combobox("setText", jsData.model.DriverName);
                    }
                });
            },
            onChange: function () {
                $('#DriverName').combobox('clear');
            }

        });
        //违章日期不能超过当前日期
        $("#ViolationTime").datebox({
            onChange: function () {
                var t1 = $("#ViolationTime").datebox("getValue");
                t1 = t1.replace(/-/g, "/");
                var da = new Date(t1);
                var MM = da.getMonth() < 9 ? "0" + (parseInt(da.getMonth()) + 1) : (parseInt(da.getMonth()) + 1);
                var dd = da.getDate() < 10 ? "0" + da.getDate() : da.getDate();
                var hh = da.getHours() < 10 ? "0" + da.getHours() : da.getHours();
                var mm = da.getMinutes() < 10 ? "0" + da.getMinutes() : da.getMinutes();
                var ss = da.getSeconds() < 10 ? "0" + da.getSeconds() : da.getSeconds();
                var t3 = da.getFullYear() + "-" + MM + "-" + dd + "  " + hh + ":" + mm + ":" + ss;


                var t2 = $.GetToday();
                if (t3 > t2) {
                    $.messager.alert('提示', '违章日期超过当前时间，请重新填写', 'info', function () {
                        $('#ViolationTime').datebox('clear');
                    });
                }
            }
        });
        //处理日期不能超过当前日期
        $("#DisposeTime").datebox({
            onChange: function () {
                var t1 = $("#DisposeTime").datebox("getValue");
                t1 = t1.replace(/-/g, "/");
                var da = new Date(t1);
                var MM = da.getMonth() < 9 ? "0" + (parseInt(da.getMonth()) + 1) : (parseInt(da.getMonth()) + 1);
                var dd = da.getDate() < 10 ? "0" + da.getDate() : da.getDate();
                var hh = da.getHours() < 10 ? "0" + da.getHours() : da.getHours();
                var mm = da.getMinutes() < 10 ? "0" + da.getMinutes() : da.getMinutes();
                var ss = da.getSeconds() < 10 ? "0" + da.getSeconds() : da.getSeconds();
                var t3 = da.getFullYear() + "-" + MM + "-" + dd + "  " + hh + ":" + mm + ":" + ss;


                var t2 = $.GetToday();
                if (t3 > t2) {
                    $.messager.alert('提示', '处理日期超过当前时间，请重新填写', 'info', function () {
                        $('#DisposeTime').datebox('clear');
                    });
                }
            }
        });
    }
    //确认新增提交方法
    function submitAddForm() {
        var isValid = $("#NewViolationList").form("validate");
        if (isValid) {
            //$('#btnadd').linkbutton('disable');
            $.messager.confirm('提示', '确认新增此违章信息吗?', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/CM/Violation/ViolationAdd")',
                        data:
                            {
                                sViolationInfo: JSON.stringify(ViolationModel(false))
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                $('#NewViolationList').dialog("close");
                                $("#gridViolation").datagrid("reload");
                            }, function () {
                                $('#btnadd').linkbutton('enable');
                            });
                        }
                    });
                } else { $('#btnadd').linkbutton('enable'); }
            });
        } else {
            $.showMsg("请填写必填项！", "提示");
        }
    }
    //确认修改提交方法
    function submitEditForm() {
        $.messager.confirm('提示', '确认修改该数据吗?', function (r) {
            if (r) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Content("~/CM/Violation/ViolationEdit")',
                    data:
                        {
                            sViolationInfo: JSON.stringify(ViolationModel(true))
                        },
                    dataType: "json",
                    success: function (jsData) {
                        $.handleJsonResult(jsData, function () {
                            $('#NewViolationList').dialog("close");
                            $("#gridViolation").datagrid("reload");
                        }, function () {
                            $('#btnadd').linkbutton('enable');
                        });
                    }
                });
            } else { $('#btnadd').linkbutton('enable'); }
        })
    }

    //获取填写所有值
    function ViolationModel(isEdit) {
        var obj = new Object();
        if (isEdit)
        obj.ID = $("#ID").val();
        obj.AmbulanceCode = $("#AmbulanceCode").val();
        obj.CenterID = $("#Center").val();
        obj.StationID = $("#Station").val();
        //obj.CenterID = $("#Center").combobox('getValue');
        //obj.StationID = $("#Station").combobox('getValue');
        obj.ActualCode = $("#ActualCode").combobox("getText");
        obj.AmbulanceNumber = $("#AmbulanceNumber").combobox("getText");      
        obj.ViolationTime = $("#ViolationTime").datebox('getValue');
        obj.ViolationPlace = $("#ViolationPlace").textbox('getText');
        obj.ViolationContent = $("#ViolationContent").textbox('getText');
        obj.DriverWorkID = $("#DriverWorkID").combobox('getText');
        obj.DriverName = $("#DriverName").combobox('getText');;
        obj.DisposeResult = $("#DisposeResult").textbox('getText');
        obj.DisposeTime = $("#DisposeTime").datebox('getValue');
        obj.Remark = $("#Remark").textbox('getText');
        obj.FillPerson = '@ViewData["name"]';
        obj.FillTime = '@ViewData["time"]';
        return obj;
    }
    //新增入口
    function initAddInfo() {
        //将修改按钮禁用
        $('#btnedit').linkbutton('disable');
        $.GID("btnedit").style.display = "none";
        $('#btnadd').linkbutton('enable');
        $.GID("btnadd").style.display = "block";
        $("#ID").val("");
        $("#AmbulancelCode").val("");
        //$("#Center").combobox("setText", "");
        //$("#Station").combobox("setText", "");
        $("#ActualCode").combobox("setValue", "");
        $("#AmbulanceNumber").combobox("setValue","");
        $("#ViolationPlace").textbox("clear");
        $("#ViolationContent").textbox("clear");
        $("#DriverWorkID").combobox("setValue","");
        $("#DriverName").combobox("setValue","");
        $("#DisposeResult").textbox("clear");
        $("#DisposeTime").datebox("setValue", "");
        $("#Remark").textbox("clear");
        $("#ViolationTime").datebox("setValue", "");
        //$.InitControlDate("#ViolationTime");
    }
    function initUpdateInfo() {
        $('#btnadd').linkbutton('disable');
        $.GID("btnadd").style.display = "none";
        $('#btnedit').linkbutton('enable');
        $.GID("btnedit").style.display = "block";
    }
</script>

<div id="NewViolationList" class="easyui-dialog" title="违章管理编辑页面" data-options="modal:true,collapsible:false,minimizable:false,maximizable:false,closed:true,resizable:false,iconCls:'icon-custom-cWuZiWeiHu'" style="width:715px;height:365px;padding:10px;">
    <input id="ID" type="hidden">
    <input id="AmbulanceCode" type="hidden">
    <input id="Center" type="hidden">
    <input id="Station" type="hidden">
    <table border="0" cellpadding="0" cellspacing="8" style="width: 99%; margin-left: 0px; margin-right: 0px; margin-top: 0px; margin-bottom: 0px">       
        <tr>
            <td style="width: 100px; text-align: right">
                车牌号码：
            </td>
            <td>             
                <input class="easyui-combobox" style="width: 160px" id="ActualCode"  data-options="required:true">
            </td>
            <td style="width: 110px; text-align: right">
                车辆编号：
            </td>
            <td>
                <input class="easyui-combobox" style="width: 160px" id="AmbulanceNumber" >
            </td>           
        </tr>
        @*<tr>
            <td style="width:100px;text-align:right">
                分中心：
            </td>
            <td>
                <input class="easyui-combobox" style="width: 160px" id="Center" data-options="required:true,editable:false">
            </td>
            <td style="width:110px;text-align:right">
                分站：
            </td>
            <td>
                <input class="easyui-combobox" style="width: 160px" id="Station" data-options="required:true,editable:false">
            </td>
        </tr>*@
        <tr>
            <td style="width: 100px; text-align: right">
                违章地点：
            </td>
            <td colspan="3">
                <input class="easyui-textbox" data-options="multiline:true, required: true" style="width:498px;height:25px" id="ViolationPlace" >
            </td>
            
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                违章内容：
            </td>
            <td colspan="3">
                <a>
                    <input id="ViolationContent" class="easyui-textbox" data-options="multiline:true,required: true" style="width:498px;height:40px">
                </a>
            </td>
        </tr>       
        <tr>
            <td style="width: 100px; text-align: right">
                责任司机工号：
            </td>
            <td>
                <input id="DriverWorkID" class="easyui-combobox" style="width:160px;" data-options="required:true">
            </td>
            <td style="width: 100px; text-align: right">
                责任司机姓名：
            </td>
            <td>
                <input id="DriverName" class="easyui-combobox" style="width:160px;" data-options="required:true,editable:false">
            </td>
            </tr>
        <tr>
            <td style="width: 110px; text-align: right">
                违章日期：
            </td>
            <td>
                <input class="easyui-datebox" style="width: 160px" id="ViolationTime" data-options="required:true">
            </td>
            <td style="width: 110px; text-align: right">
                处理日期：
            </td>
            <td>
                <input class="easyui-datebox" style="width: 160px" id="DisposeTime">
            </td>    
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                处理结果：
            </td>
            <td colspan="3">
                <a>
                    <input id="DisposeResult" class="easyui-textbox" data-options="multiline:true" style="width:498px;height:40px">
                </a>
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">备注：</td>
            <td colspan="3">
                <input id="Remark" class="easyui-textbox" data-options="multiline:true" style="width:498px;height:30px">
            </td>
        </tr>
        <tr></tr>
        <tr></tr>
        <tr>
            <td colspan="4" style="text-align:right">
                <a href="javascript:void(0)" id="btnedit" class="easyui-linkbutton" style="width:100px;margin: auto" data-options="iconCls:'icon-edit'" onclick="submitEditForm();">确认修改</a>
                <a href="javascript:void(0)" id="btnadd" class="easyui-linkbutton" style="width:100px;margin: auto" data-options="iconCls:'icon-add'" onclick="submitAddForm();">确认新增</a>
            </td>
        </tr>
    </table>
</div>